package com.shicijiaoliu.service.impl;

import com.github.pagehelper.PageHelper;
import com.shicijiaoliu.mapper.Shicimapper;
import com.shicijiaoliu.pojo.Shicitabel;
import com.shicijiaoliu.service.Shiciservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShiciserviceImol implements Shiciservice {

    @Autowired
    private Shicimapper shicimapper;

    public int getcount(String title,String dynasty,String subject,String author){
        return shicimapper.getCount(title,dynasty,subject,author);
    }
    @Override
    public void useraddshici(Shicitabel shici) {
        shicimapper.useraddshici(shici);
    }

    @Override
    public Shicitabel findByparagraphs(String paragraphs) {
        return shicimapper.findByparagraphs(paragraphs);
    }

    @Override
    public List<Shicitabel> findshiciBypage(int pagecount, int pagenumber,String title,String dynasty,String subject,String author) {
        int count = shicimapper.getCount(null,null,null,null);
        int totalpage = (int) Math.ceil((double) count/pagenumber);
        if(pagecount>totalpage || pagecount <= 0){
            return null;
        }else{
            PageHelper.startPage(pagecount,pagenumber);
            return shicimapper.findshiciBypage(title,dynasty,subject,author);
        }
    }

    @Override
    public void updateshici(Shicitabel shici) {
        shicimapper.updateshici(shici);
    }

    @Override
    public void delByid(long idS) {
        shicimapper.delByid(idS);
    }

    @Override
    public Shicitabel findByid(long idS) {
        return shicimapper.findByid(idS);
    }

    @Override
    public Shicitabel findBytitle(String title) {
        return shicimapper.findBytitle(title);
    }

    @Override
    public List<Shicitabel> findBytitle2(String title) {
        String title1 = "%" + title + "%";
        return shicimapper.findBytitle2(title1);
    }

    @Override
    public List<Shicitabel> findByname2(String title) {
        String title1 = "%" + title + "%";
        return shicimapper.findByname2(title1);
    }

    @Override
    public List<Shicitabel> findBycontent2(String title) {
        String title1 = "%" + title + "%";
        return shicimapper.findBycontent2(title1);
    }


}
